package com.edu.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.edu.dao.BaseDao;
import com.edu.dao.UserDao;
import com.edu.entity.Scar;
import com.edu.entity.Shop;
import com.edu.entity.Shopping;
import com.edu.entity.User;


public class UserDaoImpl extends BaseDao implements UserDao {

	@Override
	public int add(User user) {
		String sql="INSERT INTO users(userName,userPass,phone,position,state) "+ "VALUES(?,?,?,?,0)";
		System.out.println(sql);
		Object[] param = {user.getUserName(),user.getUserPass(),user.phone,user.position
				
		};
		int num = super.executeUpdate(sql,param);
		return num;

	
	
}

	@Override
	public List<User> reserch(String userName, String userPass) {
		Connection conn=null;
		Statement s=null;
		ResultSet rs=null;
		List<User> ulist =new ArrayList<User>();
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			String sql = "select*from users where userName='"+userName+"' and userPass='"+userPass+"'";
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				User user = new User();
				user.setUserName(rs.getString("userName"));
				user.setUserPass(rs.getString("userPass"));
				user.setState(rs.getInt("state"));
				ulist.add(user);
				System.out.println(ulist);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return ulist;
	}


	
		

	

	@Override
	public List<Shop> queryall(String cSpection) {
		String sql="select * from object WHERE cSpection='"+cSpection+"'";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setcId(rs.getInt("cId"));
				shop.setcName(rs.getString("cName"));
				shop.setcPrice(rs.getInt("cPrice"));
				shop.setcSpecial(rs.getString("cspecial"));
				shop.setcUrl(rs.getString("cUrl"));
				shop.setcSpection(rs.getString("cSpection"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;

	}

	@Override
	public List<Shop> querys() {
		String sql="select * from kind";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setKid(rs.getInt("kId"));
				shop.setkName(rs.getString("kName"));
				shop.setkUrl(rs.getString("kUrl"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> queryby() {
		String sql="select * from kuaixun";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setxId(rs.getInt("xId"));
				shop.setxName(rs.getString("xName"));
				shop.setxPoem(rs.getString("xPoem"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> querybyId() {
		String sql="select * from type";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.settId(rs.getInt("tId"));
				shop.settName(rs.getString("tName"));
				shop.settPoem(rs.getString("tPoem"));
				shop.settUrl(rs.getString("tUrl"));
				shop.setTd(rs.getString("td"));
				shop.settJiu(rs.getString("tJiu"));
				shop.settNum(rs.getString("tNum"));
				shop.setTnaiFenL(rs.getString("tnaiFen"));
				shop.settPas(rs.getString("tPass"));
				shop.settProduct(rs.getString("tProduct"));
				shop.setTs(rs.getString("ts"));
				
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> queryalls() {
		String sql="select * from img";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setImgId(rs.getInt("imgId"));
				shop.setImgName(rs.getString("imgName"));
				shop.setImgPosition(rs.getString("imgPosition"));
				shop.setImgUrl(rs.getString("imgUrl"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> select() {
		String sql="select * from querys";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setqId(rs.getInt("qId"));
				shop.setqName(rs.getString("qName"));
				shop.setqPosition(rs.getString("qPosition"));
				shop.setqUrl(rs.getString("qUrl"));
				shop.setQuse(rs.getString("quse"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> alls(int aid) {
		String sql="select * from shopdingdong WHERE sId='"+aid+"'";
		System.out.println(sql);
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setsId(rs.getInt("sId"));
				shop.setsName(rs.getString("sName"));
				shop.setsPrice(rs.getInt("sPrice"));
				shop.setsUrl(rs.getString("sUrl"));
				shop.setsType(rs.getString("sType"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> queryd() {
		String sql="select * from shopdingdong ORDER BY sId DESC";
		System.out.println(sql);
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
		
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setsId(rs.getInt("sId"));
				shop.setsName(rs.getString("sName"));
				shop.setsPrice(rs.getInt("sPrice"));
				shop.setsUrl(rs.getString("sUrl"));
				shop.setsType(rs.getString("sType"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public int added(Scar shop) {
		String sql="INSERT INTO scar(cName,cUrl,cPrice,cSum) VALUES(?,?,?,5)";
		System.out.println(sql);
		Object[] param = {shop.getcName(),shop.getcUrl(),shop.getcPrice(),		
		};
		int num = super.executeUpdate(sql,param);
		return num;
	}

	@Override
	public List<Scar> selectd(String cName) {
		String sql="select * from scar";
		System.out.println(sql);
		List<Scar> list =new ArrayList<Scar>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
		
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Scar scar= new Scar();
				scar.setcName(rs.getString("cName"));
				scar.setcPrice(rs.getString("cPrice"));
				scar.setcUrl(rs.getString("cUrl"));
				list.add(scar);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;
	}

	@Override
	public List<Shop> query(String sType) {
		String sql="select * from shopdingdong WHERE sType='"+sType+"'ORDER BY sId DESC";
		List<Shop> list =new ArrayList<Shop>();
		Connection conn=null;
		ResultSet rs=null;
		Statement s=null;
		try {
			conn = BaseDao.getConn();
			s = conn.createStatement();
			System.out.println(sql);
			rs= s.executeQuery(sql);
			while(rs.next()) {
				Shop shop = new Shop();
				shop.setsId(rs.getInt("sId"));
				shop.setsName(rs.getString("sName"));
				shop.setsPrice(rs.getInt("sPrice"));
				shop.setsUrl(rs.getString("sUrl"));
				shop.setsType(rs.getString("sType"));
				list.add(shop);
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(conn, s, rs);
		}
		return list;

	}

	


	}


